package net.app.zoneland.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import net.app.zoneland.common.core.vo.Result;
import net.app.zoneland.domain.SysRole;
import net.app.zoneland.dto.MenuDTO;
import net.app.zoneland.dto.RourcesDTO;
import net.app.zoneland.platform.mapper.SysRoleMapper;
import net.app.zoneland.platform.service.ISysRoleMenuService;
import net.app.zoneland.platform.service.ISysRoleResourceService;
import net.app.zoneland.platform.service.ISysRoleService;
import net.app.zoneland.platform.web.vo.ResourceMenuVo;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author LENOVO
 * @CreateTime 2020/12/20 13:00
 * @Version: 1.0
 */
@Service
@AllArgsConstructor
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    private final ISysRoleMenuService sysRoleMenuService;

    private final ISysRoleResourceService sysRoleResourceService;

    @Override
    public boolean update(SysRole role) {
        return false;
    }

    @Override
    public boolean delete(List<Integer> ids) {
        return false;
    }

    @Override
    public boolean add(SysRole role) {
        return false;
    }

    @Override
    public boolean update(Integer id, List<Integer> resourceIds) {
        return false;
    }

    @Override
    public IPage<SysRole> list(Page<SysRole> page, SysRole role) {
        System.out.println("查询参数："+role);
        List<SysRole> list = this.baseMapper.list(page, role);
        page.setRecords(list);
        return page;
    }

    @Override
    public Result findRourceById(Integer roleId) {
        // 根据角色查询菜单
        List<MenuDTO> byRoleId = sysRoleMenuService.findByRoleId(roleId);
        List<RourcesDTO> rourceById = sysRoleResourceService.findRourceById(roleId);
        ResourceMenuVo menus=new ResourceMenuVo();
        menus.setMenus(byRoleId);
        menus.setRources(rourceById);
        return Result.success(menus);
    }

    @Override
    public Result queryByRoleId(String roleIds) {
        List<SysRole> sysRoles = this.baseMapper.queryByRoleId(roleIds);
        return Result.success(sysRoles);
    }

}
